{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('applet', array('op' => 'post'));}">添加小程序</a></li>
	<li {if $op == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('applet', array('op' => 'display'));}">小程序列表</a></li>
</ul>
{if $op == 'display'}
<style>
.table td span{display:inline-block;margin-top:4px;}
.table td input{margin-bottom:0;}
th{
	text-align: center !important;
}
td{
	text-align: center !important;
}
</style>
<div class="main">
<form action="" method="post" class="form-horizontal" role="form">
	<div style="padding:15px;background: white;">
		<table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
					<th style="width: 90px;">序号</th>
					<th>分类</th>
					<th>标题</th>
					<th>图片</th>
					<th>状态</th>
					<th>修改/删除</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $item}
				<tr>
					<td><input type="text" class="form-control" style="text-align: center;" name="sort[{$item['id']}]" value="{$item['sort']}"></td>
					<td>{$category[$item['cid']]['title']}</td>
					<td>{$item['title']}</td>
					<td><img width="150" src="{php echo toimage($item['thumb'])}"></td>
					<td>{if $item['status']==1}<label class="label label-success">启用</label>{elseif $item['status']==2}<label class="label label-info">推荐</label>{else}<label class="label label-default">禁用</label>{/if}</td>
					<td>
						<a href="{php echo $this->createWebUrl('applet', array('op' => 'post', 'id' => $item['id']))}" title="编辑" class="btn btn-sm btn-default"><i class="fa fa-edit"></i></a>
						<a onclick="return confirm('确认删除此小程序吗？'); return false;" href="{php echo $this->createWebUrl('applet', array('op' => 'del','id' => $item['id']))}" title="删除" class="btn btn-sm btn-danger"><i class="fa fa-remove"></i></a>
					</td>
				</tr>
				{/loop}
				<tr>
	                <td colspan="5" style="text-align: left !important;">
	                	<input name="token" type="hidden" value="{$_W['token']}" />
	                    <input type="submit" class="btn btn-primary" name="submit" value="提交排序" />
	                </td>
	            </tr>
			</tbody>
		</table>
		{$pager}
	</div>
</form>
</div>
{else if $op == 'post'}
<div class="panel panel-info">
		<div class="panel-body">
			<form action="" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="id" value="{$item[id]}">
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">分类</label>
				<div class="col-sm-4">
					<select class="form-control" name="cid">
						{loop $category $cate}
							<option value="{$cate['id']}" {if $cate['id']==$item['cid']}selected{/if}>{$cate['title']}
						{/loop}
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">标题</label>
				<div class="col-sm-4">
					<input class="form-control" name="title" type="text" value="{$item['title']}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">说明</label>
				<div class="col-sm-4">
					<textarea rows="" cols="3" class="form-control" name="des">{$item['des']}</textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">图片</label>
				<div class="col-sm-4">
					{php echo tpl_form_field_image('thumb', $item['thumb'])}
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">打开类型</label>
				<div class="col-sm-4">
					<label onclick="onClickType(1);"><input type="radio" name="type" checked="checked" value="1"> 跳转</label>
					<label style="margin-left: 10px;" onclick="onClickType(2);"><input type="radio" name="type" {if $item['type']==2}checked="checked"{/if} value="2"> 扫码</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">展示背景色</label>
				<div class="col-sm-4">
					{php echo tpl_form_field_color('bgcolor', $item['bgcolor'])}
					<span class="help-block">不填则使用默认色：#178ded</span>
				</div>
			</div>
			<div class="form-group path" {if $item['type']==2}style="display: none;"{/if}>
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">小程序APPID</label>
				<div class="col-sm-4">
					<input class="form-control" name="appid" type="text" value="{$item['appid']}">
					<span class="help-block">若小程序APPID为空则跳转外链，需在小程序后台设置域名白名单</span>
				</div>
			</div>
			<div class="form-group path" {if $item['type']==2}style="display: none;"{/if}>
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">小程序路径</label>
				<div class="col-sm-4">
					<input class="form-control" name="path" type="text" value="{$item['path']}">
				</div>
			</div>
			<div class="form-group scan" {if $item['type']!=2}style="display: none;"{/if}>
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">小程序二维码</label>
				<div class="col-sm-4">
					{php echo tpl_form_field_image('qrcode', $item['qrcode'])}
				</div>
			</div>
			<div class="form-group scan" {if $item['type']!=2}style="display: none;"{/if}>
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">二维码说明</label>
				<div class="col-sm-4">
					<input class="form-control" name="qrdes" type="text" value="{$item['qrdes']}">
					<span class="help-block">弹出二维码下方的说明，不填则使用默认说明</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">排序</label>
				<div class="col-sm-4">
					<input class="form-control" name="sort" type="number" min="0" value="{$item['sort']}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">状态</label>
				<div class="col-sm-4">
					<label><input type="radio" name="status" checked="checked" value="0"> 禁用</label>
					<label style="margin-left: 10px;"><input type="radio" name="status" {if $item['status']==1}checked="checked"{/if} value="1"> 启用</label>
					<label style="margin-left: 10px;"><input type="radio" name="status" {if $item['status']==2}checked="checked"{/if} value="2"> 推荐</label>
				</div>
			</div>
			<button type="submit" class="btn btn-primary" name="submit" value="提交">保存</button>
			<input type="hidden" name="token" value="{$_W['token']}" />
			</form>
	</div>
</div>
<script type="text/javascript">
function onClickType(type){
	if(type==1){
		$('.path').show();
		$('.scan').hide();
	}else{
		$('.scan').show();
		$('.path').hide();
	}
}
</script>
{/if}
{template 'common/footer'}